﻿using System;
using System.Windows;
using System.Windows.Controls;
using JiveMessenger.CustomControls;
using System.Windows.Input;
using System.Text;
using JmShared;
using JiveMessenger.User;

namespace JiveMessenger.Views
{
    /// <summary>
    /// Interaction logic for MessagesPage.xaml
    /// </summary>
    public partial class MessagesPage : Page
    {
        public int AgeLimit { get; set; }

        public int CountLimit { get; set; }
       
        public PcUserSettings UserSettings {get;set;}
        public MessagesPage(IClient currentClient)
       { 
            UserSettings = currentClient.UserSettings;
            this.AgeLimit = UserSettings.OfflineMessagesAgeLimit.GetValueOrDefault();
            this.CountLimit = UserSettings.OfflineMessagesCountLimit.GetValueOrDefault();
            //AgeLimit = Properties.Settings.Default.SettingOfflineMessagesAgeLimit;
            //CountLimit = Properties.Settings.Default.SettingOfflineMessagesCountLimit;
            InitializeComponent();
           
            //this.TxtBoxOfflineMessageAgeLimit.DataContext = this;
            //this.TxtBoxOfflineMessageCount.DataContext = this;
        }

        private void Shortcut_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            TextBox tb = (TextBox)sender;
            // The text box grabs all input.
            e.Handled = true;

            // Fetch the actual shortcut key.
            Key key = (e.Key == Key.System ? e.SystemKey : e.Key);

            // Ignore modifier keys.
            if (key == Key.LeftShift || key == Key.RightShift
                || key == Key.LeftCtrl || key == Key.RightCtrl
                || key == Key.LeftAlt || key == Key.RightAlt
                || key == Key.LWin || key == Key.RWin)
            {
                return;
            }

            // Build the shortcut key name.
            StringBuilder shortcutText = new StringBuilder();
            if ((Keyboard.Modifiers & ModifierKeys.Control) != 0)
            {
                shortcutText.Append("Ctrl+");
            }
            if ((Keyboard.Modifiers & ModifierKeys.Shift) != 0)
            {
                shortcutText.Append("Shift+");
            }
            if ((Keyboard.Modifiers & ModifierKeys.Alt) != 0)
            {
                shortcutText.Append("Alt+");
            }
            shortcutText.Append(key.ToString());

            // Update the text box.
            tb.Text = shortcutText.ToString();
        }

    }
}
